package hivMultiCompartment;

import java.util.HashSet;


/**
 * This is the grid world for small particles in spatial compartment
 * such as virus particles.
 * There is an array list in each grid cell, and multiple virus can be in the same
 * cell by being in the array.
 */

public class SmallParticleGrid extends SemiTorus {
	
	public SmallParticleGrid(int sizeX, int sizeY, Model aModel, Organ2DSpace aOrgan) {
		super(sizeX, sizeY, aModel, aOrgan);
		initVirusList();
	}
	
	/**
	 * each grid position has an hash set of virus
	 */
	public void initVirusList() {
		for(int i = 0; i< xSize; ++i){
			for (int j = 0; j < ySize; ++j) {
				HashSet<Virus> list = new HashSet<Virus> ();
				this.putObjectAt(i, j, list);
			}
		}
	}
	
	
	public boolean addObjectAt (int x, int y, ObjectInGrid o) {
		boolean result = true;
		x = processedX(x);
		y = processedY(y);
		o.setX(x);
		o.setY(y);
		HashSet<Virus> list = (HashSet<Virus>)getObjectAt(x, y);
		list.add((Virus)o);
		return result;
	}
	
	/**
	 * remove ObjectInGrid o from grid
	 * @param o
	 */
	public void removeObjectFromGrid (ObjectInGrid o) {
		HashSet<Virus> list = (HashSet<Virus>)getObjectAt(o.getX(), o.getY());
		list.remove((Virus)o);
	}
	
}
